import { URLData } from "../../../../scripts/URLData"
import { UserInfo } from "../proto/proto"

export class KugoUserDataModel { 
    private _selfUserId :string = "0"
    constructor(){
        this._selfUserId = URLData.userId
        this._userInfos = new Map()
    }

    get selfId(){
        return this._selfUserId
    }

    private _userInfos:Map<string,UserInfo> = null
    addUserInfo(user:UserInfo){
        this._userInfos.set(user.Data.UserId , user)
    }

    /**默认返回自己的 */
    getUserById(userId?:string){
        userId = userId || this._selfUserId
        return this._userInfos.get(userId)
    }
    
    getUserBySeatId(seatId:number){
        for(let [_, user] of this._userInfos){
            if (user.SeatId == seatId) {
                return user
            }
        }
    }

    getAllUser(){
        return this._userInfos
    }

    userReady(seatId:number,state){
        let user = this.getUserBySeatId(seatId)
        user.ReadyState = state
    }

    refreshLeftTime(seatId:number,leftTime:number){
        // let user = this.getUserBySeatId(seatId)
        // user.LeftTime = leftTime
    }
}   